
/**
 * returns the ids for left and right box
 * @param 		string		idPrefix
 * @returns 	mixed		ids
 */
function getIds(idPrefix){
	var ids = {};
	ids.LEFT = '#' + idPrefix + '_ASSIGNBOX_LEFT';
	ids.RIGHT = '#' + idPrefix + '_ASSIGNBOX_RIGHT';
	return ids;
}

/**
 * moves the selected entries from left to right
 * @param idPrefix
 */
function moveRight(idPrefix){
	var ids = getIds(idPrefix);
	move(ids.LEFT, ids.RIGHT, 'R');
}


/**
 * moves the selected entries from right to left
 * @param idPrefix
 */
function moveLeft(idPrefix){
	var ids = getIds(idPrefix);
	move(ids.RIGHT, ids.LEFT, 'L');
}


/**
 * selects all entries from the left box and moves all right
 * @param 		string		idPrefix
 */
function moveAllRight(idPrefix){
	var ids = getIds(idPrefix);
	$(ids.LEFT + ' option').attr('selected', 'selected');
	moveRight(idPrefix);
}


/**
 * selects all entries from the right box and moves all left
 * @param 		string		idPrefix
 */
function moveAllLeft(idPrefix){
	var ids = getIds(idPrefix);
	$(ids.RIGHT + ' option').attr('selected', 'selected');
	moveLeft(idPrefix);
}


/**
 * moves all selected options
 * @param 		string		idFrom
 * @param 		stringid    To
 * @param		string		dir
 */
function move(idFrom, idTo, dir){
	var selectedOptions = $(idFrom + ' option:selected');

	selectedOptions.each(function(){
		var optionValue = $(this).val();
		var optionText = $(this).text();
		$(this).remove();

		$(idTo).append($("<option/>", {
			value: optionValue,
			text: optionText
		}));
		
		if (dir.toUpperCase(dir) == 'L' && typeof assignBoxSwitchLeft == 'function')		//call the function assignboxSwitch with the switched value
			assignBoxSwitchLeft(optionValue);
		
		if (dir.toUpperCase(dir) == 'R' && typeof assignBoxSwitchRight == 'function')		//call the function assignboxSwitch with the switched value
			assignBoxSwitchRight(optionValue);
	});
}